import pymongo
import common.gyblog as log

LOG = log.get_logger()

CONNECTION_STR = 'mongodb://192.168.0.196:27017/?readPreference=primary&appname=MongoDB%20Compass%20Community&ssl=false'
DATA_BASE = 'movies_record'  # 数据库名
DB_COL = 'fc2club_url'  # 表名

SELLER = 'まるきゅう商事'
URL = 'https://fc2hub.com/en/seller/19889/%E3%81%BE%E3%82%8B%E3%81%8D%E3%82%85%E3%81%86%E5%95%86%E4%BA%8B'
PAGE = '1'


def insert_url(seller, url, page):
    # 连接数据库
    db_client = pymongo.MongoClient(CONNECTION_STR)
    db_database = db_client[DATA_BASE]
    db_col = db_database[DB_COL]

    query = {'seller': seller}
    query_ans = list(db_col.find(query))

    if len(query_ans) == 0:
        dic = {'seller': seller, 'url': url, 'page': page, 'last_time': ''}
        print(dic)
        db_col.insert_one(dic)
    else:
        print('{}已存在'.format(seller))
    db_client.close()


insert_url(SELLER, URL, PAGE)
